<template>
  <div class="page">
    <van-nav-bar title="数据汇集" left-text="返回" @click-left="goBack">
      <van-icon slot="left" name="arrow-left" size="20" />
    </van-nav-bar>
    <div class="content">
      <a1-box :total={value:this.box1Data.totalValue,rate:this.box1Data.totalRate}
        :day= total2-box1Data.dayValue
        :month= total2-box1Data.monthValue />
      <a2-chart :base5Name=this.baseTop5Name :base5Value1=this.baseTop5Value_zl />
      <a3-box
        :cardData={base:(this.box3Data.base/100000000).toFixed(2),std:(this.box3Data.std/100000000).toFixed(2),stc:(this.box3Data.stc/100000000).toFixed(2)} />
      <a4-chart />
      <a5-chart />
      <a6-chart :baseTop5Name=baseTop5Name :baseTop5Value=baseTop5Value />
    </div>
  </div>
</template>

<script>
import API from "@/api/assemble";
import A1Box from "@/views/assemble/modules/a1-box";
import A3Box from "@/views/assemble/modules/a3-box";
import A6Chart from "@/views/assemble/modules/a6-chart";
import A5Chart from "@/views/assemble/modules/a5-chart";
import A4Chart from "@/views/assemble/modules/a4-chart";
import A2Chart from "@/views/assemble/modules/a2-chart";
/**
 * 数据汇集
 */
export default {
  name: "assembleIndex",
  components: { A2Chart, A4Chart, A5Chart, A6Chart, A3Box, A1Box },
  data() {
    return {
      box1Data: {
        totalValue: 0,
        totalRate: 0,
        monthValue: 0,
        monthRate: 0,
        dayValue: 0,
        dayRate: 0,
      },
      box3Data: {
        base: 0,
        std: 0,
        stc: 0,
      },
      timer: null,
      baseTop5Name: [], //Top5数据名
      baseTop5Value: [], //Top5数据值
      baseTop5Value_zl: [], //box2图表基础类数据值-总量
      baseTop5Value_dy: [], //box2图表基础类数据值-月总量
      total2: 0, //小總量
    };
  },

  methods: {
    goBack() {
      this.$router.push({ path: "/" });
    },
    getBoxData() {
      //总量
      let handleV1 = (res) => {
        let tysjldbm = Object.values(res.data.body.data[0])[0];
        this.box1Data.totalValue += tysjldbm;
        this.total2 += tysjldbm;
        this.box3Data.stc += tysjldbm;
      };
      let handleV2 = (res) => {
        let tyqslxbm = Object.values(res.data.body.data[0])[0];
        this.box1Data.totalValue += tyqslxbm;
        this.total2 += tyqslxbm;

        this.box3Data.stc += tyqslxbm;
      };
      let handleV3 = (res) => {
        let bzqsldbm = Object.values(res.data.body.data[0])[0];
        this.box1Data.totalValue += bzqsldbm;
        this.box3Data.std += bzqsldbm;
      };
      let handleV4 = (res) => {
        let bzqslxbm = Object.values(res.data.body.data[0])[0];
        this.box1Data.totalValue += bzqslxbm;
        this.box3Data.std += bzqslxbm;
      };
      let handleV5 = (res) => {
        let jccrkk = Object.values(res.data.body.data[0])[0];
        this.box1Data.totalValue += jccrkk;
        this.box3Data.base += jccrkk;
        this.baseTop5Value.push((jccrkk / 100000000).toFixed(2));
        this.baseTop5Value_zl.push(jccrkk);
        this.baseTop5Value_dy.push(jccrkk);
        this.baseTop5Name.push("人口");
      };
      let handleV6 = (res) => {
        let frksjl = Object.values(res.data.body.data[0])[0];
        this.box1Data.totalValue += frksjl;
        this.box3Data.base += frksjl;
        this.baseTop5Value.push((frksjl / 100000000).toFixed(2));
        this.baseTop5Value_zl.push(frksjl);
        this.baseTop5Value_dy.push(frksjl);
        this.baseTop5Name.push("法人");
      };
      let handleV7 = (res) => {
        let kjxxsjl = Object.values(res.data.body.data[0])[0];
        this.box1Data.totalValue += kjxxsjl;
        this.box3Data.base += kjxxsjl;
        this.baseTop5Value.push((kjxxsjl / 100000000).toFixed(2));
        this.baseTop5Value_zl.push(kjxxsjl);
        this.baseTop5Value_dy.push(kjxxsjl);
        this.baseTop5Name.push("地理空间");
      };
      let handleV8 = (res) => {
        let xyxxsjl = Object.values(res.data.body.data[0])[0];
        this.box1Data.totalValue += xyxxsjl;
        this.box3Data.base += xyxxsjl;
        this.baseTop5Value.push((xyxxsjl / 100000000).toFixed(2));
        this.baseTop5Value_zl.push(xyxxsjl);
        this.baseTop5Value_dy.push(xyxxsjl);
        this.baseTop5Name.push("信用信息");
      };
      let handleV9 = (res) => {
        let dzzzsjl = Object.values(res.data.body.data[0])[0];
        this.box1Data.totalValue += dzzzsjl;
        this.box3Data.base += dzzzsjl;
          this.box1Data.totalValue += 900000000;
        this.baseTop5Value.push((dzzzsjl / 100000000).toFixed(2));
        this.baseTop5Value_zl.push(dzzzsjl);
        this.baseTop5Value_dy.push(dzzzsjl);
        this.baseTop5Name.push("证照");
      };
      API.getBox1_v1().then(handleV1);
      API.getBox1_v2().then(handleV2);
      API.getBox1_v3().then(handleV3);
      API.getBox1_v4().then(handleV4);
      API.getBox1_v5().then(handleV5);
      API.getBox1_v6().then(handleV6);
      API.getBox1_v7().then(handleV7);
      API.getBox1_v8().then(handleV8);
      API.getBox1_v9().then(handleV9);
      //昨日总量
      let handleV1_zr = (res) => {
        this.box1Data.dayValue +=
          res.data.body.data[0] == undefined ? 0 : res.data.body.data[0].tysjldbm;

      };
      let handleV2_zr = (res) => {
        this.box1Data.dayValue +=
          res.data.body.data[0] == undefined ? 0 : res.data.body.data[0].tysjldbm;

      };
      // let handleV3_zr = (res) => {
      //   this.box1Data.dayValue +=
      //     res.data.body.data[0] == undefined ? 0 : res.data.body.data[0].tysjldbm;
      //
      // };
      // let handleV4_zr = (res) => {
      //   this.box1Data.dayValue +=
      //     res.data.body.data[0] == undefined ? 0 : res.data.body.data[0].tysjldbm;
      //     console.log(res.data.body.data)
      // };
      // let handleV5_zr = (res) => {
      //   this.box1Data.dayValue +=
      //     res.data.body.data[0] == undefined ? 0 : res.data.body.data[0].jcczl;
      //
      // };
      // let handleV6_zr = (res) => {
      //   this.box1Data.dayValue +=
      //     res.data.body.data[0] == undefined ? 0 : res.data.body.data[0].jcczl;
      //     console.log(res.data.body.data)
      // };
      // let handleV7_zr = (res) => {
      //   this.box1Data.dayValue +=
      //     res.data.body.data[0] == undefined ? 0 : res.data.body.data[0].jcczl;
      //
      // };
      // let handleV8_zr = (res) => {
      //   this.box1Data.dayValue +=
      //     res.data.body.data[0] == undefined ? 0 : res.data.body.data[0].jcczl;
      //
      // };
      // let handleV9_zr = (res) => {
      //   this.box1Data.dayValue +=
      //     res.data.body.data[0] == undefined ? 0 : res.data.body.data[0].jcczl;
      //
      // };
      API.getBox2_v1().then(handleV1_zr);
      API.getBox2_v2().then(handleV2_zr);
      // API.getBox2_v3().then(handleV3_zr);
      // API.getBox2_v4().then(handleV4_zr);
      // API.getBox2_v5().then(handleV5_zr);
      // API.getBox2_v6().then(handleV6_zr);
      // API.getBox2_v7().then(handleV7_zr);
      // API.getBox2_v8().then(handleV8_zr);
      // API.getBox2_v9().then(handleV9_zr);
      //上月总量
      let handleV1_sy = (res) => {
        this.box1Data.monthValue +=
          res.data.body.data[0] == undefined ? 0 : res.data.body.data[0].tysjldbm;

      };
      let handleV2_sy = (res) => {
        this.box1Data.monthValue +=
          res.data.body.data[0] == undefined ? 0 : res.data.body.data[0].tysjldbm;

      };
      // let handleV3_sy = (res) => {
      //   this.box1Data.monthValue +=
      //     res.data.body.data[0] == undefined ? 0 : res.data.body.data[0].tysjldbm;
      //
      // };
      // let handleV4_sy = (res) => {
      //   this.box1Data.monthValue +=
      //     res.data.body.data[0] == undefined ? 0 : res.data.body.data[0].tysjldbm;
      //
      // };
      // let handleV5_sy = (res) => {
      //   let tmp =
      //     res.data.body.data[0] == undefined ? 0 : res.data.body.data[0].jcczl;
      //   this.box1Data.monthValue += tmp;
      //   this.baseTop5Value_dy.jccrkk -= tmp;
      //
      // };
      // let handleV6_sy = (res) => {
      //   let tmp =
      //     res.data.body.data[0] == undefined ? 0 : res.data.body.data[0].jcczl;
      //   this.box1Data.monthValue += tmp;
      //   this.baseTop5Value_dy.frksjl -= tmp;
      //
      // };
      // let handleV7_sy = (res) => {
      //   let tmp =
      //     res.data.body.data[0] == undefined ? 0 : res.data.body.data[0].jcczl;
      //   this.box1Data.monthValue += tmp;
      //   this.baseTop5Value_dy.kjxxsjl -= tmp;
      //
      // };
      // let handleV8_sy = (res) => {
      //   let tmp =
      //   res.data.body.data[0] == undefined ? 0 : res.data.body.data[0].jcczl;
      //   this.box1Data.monthValue += tmp;
      //   this.baseTop5Value_dy.xyxxsjl -= tmp;
      //
      // };
      // let handleV9_sy = (res) => {
      //   let tmp =
      //     res.data.body.data[0] == undefined ? 0 : res.data.body.data[0].jcczl;
      //   this.box1Data.monthValue += tmp;
      //   this.baseTop5Value_dy.dzzzsjl -= tmp;
      //
      //
      // };
      API.getBox3_v1().then(handleV1_sy);
      API.getBox3_v2().then(handleV2_sy);
      // API.getBox3_v3().then(handleV3_sy);
      // API.getBox3_v4().then(handleV4_sy);
      // API.getBox3_v5().then(handleV5_sy);
      // API.getBox3_v6().then(handleV6_sy);
      // API.getBox3_v7().then(handleV7_sy);
      // API.getBox3_v8().then(handleV8_sy);
      // API.getBox3_v9().then(handleV9_sy);

      console.log(this.box1Data.totalValue-this.box1Data.dayValue)
    },
  },

  mounted() {
    // this.getBoxData(); //获取盒子数据
    this.timer = setInterval(this.getBoxData(), 30000); // 设置周期触发任务
  },
  beforeDestroy() {
    clearInterval(this.timer);
    this.timer = null;
  },
};
</script>

<style lang="less" scoped>
.page {
  .content {
    background-color: #ffffff;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    padding: 10px 10px;
    .content-card {
      margin: 10px 0;
      border: 1px solid #f2f2f2;
      background-color: #ffffff;
      box-shadow: 0 4px 8px rgba(90, 163, 236, 0.14);
      border-radius: 4px;
    }
  }
}
</style>
